home *** CD-ROM | disk | FTP | other *** search
/ Web Page Construction Kit 3.0 / Web Page Construction Kit 3.0.iso / pc / source / 3rdparty / java / jdesnpro / data.1 / JDPLayout4.java < prev    next >
Encoding:
Text File  |  1996-07-29  |  11.8 KB  |  384 lines

  1. >XXX0389  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13. import java.util.Date;
  14.  
  15.  
  16. >003public class <JDPUserBill> extends JDPClassLayout {
  17.  
  18.     JDPUser user;
  19.     JDPJagg jaggSQL;
  20.     JDPTextGrid tableContents;
  21.     JDPWhereClause jdpWhereClause;
  22.  
  23.     String[] psortChoice;
  24.     String[] pdisplayChoice;
  25.     int itemIndex;
  26.     boolean insertRequested = false;
  27.     boolean deleteRequested = false;
  28.     String pfromWhereClause;
  29.     String[][] rowKey;
  30.     int keyCount;
  31.     int prevColumnCount;
  32. >119    int columnCount = <columnCount>;
  33.  
  34.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  35.  
  36.         this.user = user;
  37.         //
  38.         //  Set JAGG settings for this class
  39.         //
  40.         jaggSQL = new JDPJagg(user.jaggPath);
  41.         jaggSQL.setNULL("space");
  42. >995        jaggSQL.setMRW("<maxRows>");
  43. >998        jaggSQL.setDSN("<datasource>");
  44. >999        jaggSQL.setCSTR("<connectstr>");
  45.  
  46.         setLayout(new BorderLayout());
  47.         setFont(user.plainFont);
  48.  
  49.         Panel mainPanel = new Panel();
  50.         mainPanel.setLayout(new BorderLayout());
  51.         Panel centerMainPanel = new Panel();
  52.         centerMainPanel.setLayout(new BorderLayout());
  53.  
  54.         //
  55.         //  Create a new instance of a Grid
  56.         //
  57.         tableContents = new JDPTextGrid(user);
  58.         mainPanel.add("Center",tableContents);
  59.         centerMainPanel.add("Center",mainPanel);
  60.         
  61.         //
  62.         //  Define parameters for JDPWhereClause
  63.         //
  64. >016        String[] pchooseFrom = new String[<7>];
  65. >017        pchooseFrom[<0>] = "<Account Name>";
  66.  
  67. >018        String[] pactualchooseFrom = new String[<7>];
  68. >019        pactualchooseFrom[<0>] = "<username>";
  69.  
  70. >020        String[][] pmatchUsing = new String[<7>][<7>];
  71. >021        pmatchUsing[<0>][<0>] = "<Begins with>";
  72.  
  73. >022        String[][] pactualmatchUsing = new String[<7>][<7>];
  74. >023        pactualmatchUsing[<0>][<0>] = "< like >";
  75.  
  76. >024        boolean[] constantIsString = new boolean[<7>];
  77. >025        constantIsString[<0>] = <true>;
  78.  
  79. >026        int[] constantLength = new int[<7>];
  80. >027        constantLength[<0>] = <20>;
  81.  
  82.         //
  83.         //  Add JDPWhereClause search panel
  84.         //
  85.         if (pchooseFrom.length > 0) {
  86. >028            jdpWhereClause = new JDPWhereClause(user, "<UserBill>", false, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  87.                                                 pmatchUsing, pactualmatchUsing, null, null,
  88.                                                 constantLength, constantIsString);
  89.             centerMainPanel.add("North",jdpWhereClause);
  90.         }
  91.  
  92. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",centerMainPanel,"North"));
  93.         loadGrid();
  94.  
  95.         // repaint the panel
  96.         targetPanel.add("Center",this);
  97.         targetPanel.paintAll(targetPanel.getGraphics());
  98.         //
  99.         //  Add the handle to this panel to the global vector so other panels can
  100.         //  access this one
  101.         //
  102.         user.gParm.addElement(this);
  103.     }
  104.  
  105.     //
  106.     //  Handle screen events
  107.     //
  108.     public boolean handleEvent(Event e) {
  109.  
  110.         switch (e.id) {
  111.         case Event.ACTION_EVENT:
  112.             if (e.target instanceof Button) {
  113.                 String choice = (String)e.arg;
  114.                 if (choice.trim().compareTo("Search") == 0) {
  115.                     newSearch();
  116.                     return true;
  117.                 }
  118.                 return false;
  119.             }
  120.             if (e.target instanceof Choice) {
  121.                 return true;
  122.             }
  123.             if (e.target instanceof TextField) {
  124.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  125.                     newSearch();
  126.                     return true;
  127.                 }
  128.                 return true;
  129.             }
  130.             return false;
  131.  
  132.         case Event.WINDOW_EXPOSE:
  133.             if (e.target instanceof JDPTabSelectTopPanel) {
  134.                 //
  135.                 //  This is where you place code to get executed when this panel is
  136.                 //  reactivated from the tab menu
  137.                 //
  138.                 return true;
  139.             }
  140.             return false;
  141.  
  142.         default:
  143.             return false;
  144.  
  145.         }
  146.     }
  147.  
  148.     //
  149.     //  Retrieve the handle to another panel so as to be able to interact with it
  150.     //
  151.     public void retrieveHandle() {
  152.  
  153.         for (int ix=0; ix<user.gParm.size(); ix++) {
  154.             //
  155.             //  Activate the next four lines of code to retrieve the handle to another 
  156.             //  Panel within your JDP system. Of course you should declare the variable 
  157.             //  at the top of this source instead of within this method so you can 
  158.             //  access it from all the methods within this class. You only need to 
  159.             //  substitute DemoClass with the name ouf your class. You should call this 
  160.             //  method from somewhere else in this class. To access a variable from 
  161.             //  your resulting class use:
  162.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  163.             //
  164. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  165. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  166. //                return;
  167. //            }
  168.         }
  169.     }
  170.  
  171.     //
  172.     //  The search button was pressed so rerun the query with the new search criteria
  173.     //
  174.     public void newSearch() {
  175.  
  176.         loadGrid();
  177.     }
  178.  
  179.     //
  180.     //  Load the grid with the specified parameters and selected data
  181.     //
  182.     public void loadGrid() {
  183.  
  184.         StringTokenizer stok;
  185.         int recCount = 0;
  186.         Vector results = new Vector();
  187.         String sep = jaggSQL.getSEP();
  188.         int actualRows = 0;
  189.         String row;
  190.         float[][] worksubTotal;
  191.         float[][] workgrandTotal;
  192.  
  193.         Vector columns = new Vector();
  194.         Vector indexes = new Vector();
  195.  
  196. >100        String SQL = <SELECT>;
  197.  
  198.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  199.  
  200.         recCount = jaggSQL.execSQL(SQL, results);
  201.  
  202.         if(recCount == -1) {
  203.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
  204.             System.out.println("loadGrid SQL: " + SQL);
  205.             return;
  206.         }
  207.  
  208.         //
  209.         //  Initialise result arrays
  210.         //
  211.         actualRows = jaggSQL.getRowCount();
  212.         tableContents.currentText = new String[columnCount][actualRows+30];
  213.         tableContents.cellFont = new Font[columnCount][actualRows+30];
  214.         tableContents.gridColor = Color.white;
  215.         boolean[] totalThisColumn = new boolean[columnCount];
  216.         //
  217.         //  If we haven't already initialise the grid settings
  218.         //
  219.         if (columnCount != prevColumnCount) {
  220.             prevColumnCount = columnCount;
  221.             setGridSettings();
  222.         }
  223.         String[] lastItem = new String[columnCount];
  224. >125        boolean[] subTotal = new boolean[<>];
  225. >125        boolean[] grandTotal = new boolean[<>];
  226. >126        int orderBy = <>;
  227. >127        subTotal[<>] = <>;
  228. >128        grandTotal[<>] = <>;
  229. >129        totalThisColumn[<>] = <>;
  230.         //
  231.         //  Load arrays and result List
  232.         //
  233.         worksubTotal = new float[1][1];
  234.         workgrandTotal = new float[1][1];
  235.         int xOffset = 0;
  236.         int    xIncrement = 0;
  237.         int titlePos = (int)(columnCount/2)-1;
  238.         if (titlePos < 0) titlePos = 0;
  239. >124        tableContents.currentText[titlePos][1] = "<>";
  240.         tableContents.cellFont[titlePos][1] = new Font(user.plainFont.getName(),Font.BOLD,user.plainFont.getSize()+4);
  241.         for (int iy=0; iy<columnCount; iy++) {
  242.             tableContents.cellFont[iy][3] = user.boldFont;
  243.         }
  244. >101        tableContents.currentText[<ix>][3] = "<>";
  245.         xOffset = 4;
  246.         worksubTotal = new float[orderBy][columnCount];
  247.         workgrandTotal = new float[orderBy][columnCount];
  248.         int ix;
  249.         for (ix=0; ix<actualRows; ix++) {
  250.             row = (String)results.elementAt(ix);
  251.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  252.                 stok = new StringTokenizer(row);
  253.                 for (int iy=0; iy<columnCount; iy++) {
  254.                     tableContents.currentText[iy][ix+xOffset] = stok.nextToken(sep).trim();
  255.                 }
  256.                 for (int iy=columnCount-1; iy>=0; iy--) {
  257.                     String thisItem = tableContents.currentText[iy][ix+xOffset];
  258.                     if ((orderBy > iy) && (ix > 0)) {
  259.                         if (thisItem.equals(lastItem[iy])) {
  260.                             tableContents.currentText[iy][ix+xOffset] = "";
  261.                         } else {
  262.                             if (subTotal[iy]) {
  263.                                 for (int iz=0; iz<columnCount; iz++) {
  264.                                     tableContents.currentText[iz][ix+xOffset+1] = tableContents.currentText[iz][ix+xOffset];
  265.                                     tableContents.currentText[iz][ix+xOffset] = "";
  266.                                     tableContents.cellFont[iz][ix+xOffset+1] = tableContents.cellFont[iz][ix+xOffset];
  267.                                     tableContents.cellFont[iz][ix+xOffset] = null;
  268.                                 }
  269.                                 tableContents.currentText[iy][ix+xOffset] = "Subtotal";
  270.                                 tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  271.                                 for (int iw=iy+1; iw<columnCount; iw++) {
  272.                                     if (totalThisColumn[iw]) {
  273.                                         tableContents.currentText[iw][ix+xOffset] = user.u.str(worksubTotal[iy][iw],11,3).trim();
  274.                                         tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  275.                                     }
  276.                                     worksubTotal[iy][iw] = 0;
  277.                                 }
  278.                                 xOffset += 1;
  279.                             }
  280.                             tableContents.currentText[iy][ix+xOffset] = thisItem;
  281.                         }
  282.                     }
  283.                     if ((orderBy > 0) && (ix > 0)) {
  284.                         try {
  285.                             float tempfloat = Float.valueOf(lastItem[iy]).floatValue();
  286.                             for (int iz=0; iz<orderBy; iz++) {
  287.                                 worksubTotal[iz][iy] += tempfloat;
  288.                                 workgrandTotal[iz][iy] += tempfloat;
  289.                             }
  290.                         } catch(Exception e) { 
  291.                         }
  292.                     }
  293.                     lastItem[iy] = thisItem;
  294.                 }
  295.             }
  296.         }
  297.  
  298.         for (int iy=0; iy<columnCount; iy++) {
  299.             try {
  300.                 float tempfloat = Float.valueOf(lastItem[iy]).floatValue();
  301.                 for (int iz=0; iz<orderBy; iz++) {
  302.                     worksubTotal[iz][iy] += tempfloat;
  303.                     workgrandTotal[iz][iy] += tempfloat;
  304.                 }
  305.             } catch(Exception e) { 
  306.             }
  307.         }
  308.         for (int iy=columnCount-1; iy>=0; iy--) {
  309.             if (orderBy > iy) {
  310.                 if (subTotal[iy]) {
  311.                     tableContents.currentText[iy][ix+xOffset] = "Subtotal";
  312.                     tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  313.                     for (int iw=iy+1; iw<columnCount; iw++) {
  314.                         if (totalThisColumn[iw]) {
  315.                             tableContents.currentText[iw][ix+xOffset] = user.u.str(worksubTotal[iy][iw],11,3).trim();
  316.                             tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  317.                         }
  318.                     }
  319.                     xOffset += 1;
  320.                 }
  321.             }
  322.         }
  323.         for (int iy=columnCount-1; iy>=0; iy--) {
  324.             if (orderBy > iy) {
  325.                 if (grandTotal[iy]) {
  326.                     tableContents.currentText[iy][ix+xOffset] = "Total";
  327.                     tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  328.                     for (int iw=iy+1; iw<columnCount; iw++) {
  329.                         if (totalThisColumn[iw]) {
  330.                             tableContents.currentText[iw][ix+xOffset] = user.u.str(workgrandTotal[iy][iw],11,3).trim();
  331.                             tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  332.                         }
  333.                     }
  334.                     xOffset++;
  335.                 }
  336.             }
  337.         }
  338.  
  339.         tableContents.newTable();
  340.  
  341.         //
  342.         //  Clear status message
  343.         //
  344.         user.mainmsg.clearStatusMsg();
  345.     }
  346.  
  347.     //
  348.     //  Set up the parameters for this grid
  349.     //
  350.     public void setGridSettings() {
  351.  
  352.         tableContents.columnHeader = null;
  353.         tableContents.columnHeaderStyle = new int[columnCount];
  354.         tableContents.columnStyle = new int[columnCount];
  355.         tableContents.columnHeaderColor = new Color[columnCount];
  356.         tableContents.columnColor = new Color[columnCount];
  357.         tableContents.columnBGColor = new Color[columnCount];
  358.         tableContents.columnProtected = new boolean[columnCount];
  359.         tableContents.columnWidth = new int[columnCount];
  360.         tableContents.rightJustify = new boolean[columnCount];
  361.         tableContents.rowHeader = null;
  362.         tableContents.columnHeight = null;
  363.         for (int ix=0; ix<columnCount; ix++) {
  364.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  365.             tableContents.columnStyle[ix] = Font.PLAIN;
  366.             tableContents.columnHeaderColor[ix] = Color.black;
  367.             tableContents.columnColor[ix] = Color.black;
  368.             tableContents.columnBGColor[ix] = Color.white;
  369.             tableContents.columnStyle[ix] = Font.PLAIN;
  370.         }
  371. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  372. >103        tableContents.columnStyle[<ix>] = <>;
  373. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  374. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  375. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  376. >107        tableContents.columnProtected[<ix>] = <>;
  377. >108        tableContents.columnWidth[<ix>] = <>;
  378. >109        tableContents.rightJustify[<ix>] = <>;
  379.  
  380.     }
  381.  
  382.  
  383. }
  384.